package com.gui.design.singleton;

import java.lang.reflect.Constructor;

public class SingletonDemo1 {

    public static void main(String[] args) throws Exception {
        Singleton singleton = Singleton.getInstance();
        Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton1);
        System.out.println(singleton);
        System.out.println("==============");

        Constructor<Singleton> constructor = Singleton.class.getDeclaredConstructor(new Class[]{});
        constructor.setAccessible(true);
        Singleton singleton2 = constructor.newInstance(new Object[]{});
        System.out.println(singleton2);
    }


    private static class Singleton {
        public static Singleton singleton = new Singleton();

        private Singleton() {

        }

        public static Singleton getInstance() {
            return singleton;
        }
    }

}


